package SuanFa;

import java.util.Random;
import java.util.Scanner;

/**
 * Created by asd73 on 2017/8/27.
 */
public class Main {
    public static void main(String[] args) {
        Random ran = new Random();
        int[] sort = new int[10];
        for(int i = 0 ; i < 10 ; i++){
            sort[i] = ran.nextInt(50);
        }
        System.out.print("排序前的数组为");
        for(int i : sort){
            System.out.print(i+" ");
        }
        buddleSort(sort);
        System.out.println();
        System.out.print("排序后的数组为");
        for(int i : sort){
            System.out.print(i+" ");
        }
    }

    /**
     * 冒泡排序
     * @param sort
     */
    private static void buddleSort(int[] sort){
        for(int i=1;i<sort.length;i++){
            for(int j=0;j<sort.length-i;j++){
                if(sort[j]>sort[j+1]){
                    int temp = sort[j+1];
                    sort[j+1] = sort[j];
                    sort[j] = temp;
                }
            }
        }
    }
}

/**
 * 冒泡排序
 */
class Paixu{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Input num");
        String s = scanner.nextLine();
        String[] s1 = s.split(" ");
        int[] a = new int[s1.length];
        for (int i=0;i<s1.length;i++){
            a[i]=Integer.parseInt(s1[i]);
        }

        int temp=0;
        for (int i=0;i<s1.length-1;i++){
            for (int j=0;j<s1.length-1-i;j++){
                if (a[j]>a[j+1]){
                    temp=a[j];
                    a[j]=a[j+1];
                    a[j+1]=temp;
                }
            }
        }
        for (int i:a){
            System.out.print(i+" ");
        }
    }


}